/**
 * 
 */
package com.cdhospital.websitecontroller;

import java.util.List;

import com.cdhospital.Model.Expert;
import com.cdhospital.adminservice.ExpertService;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

/**
 * @author 17994
 *
 */
public class WebsiteExpertController extends Controller {
	static ExpertService service=new ExpertService();
	public void index(){
		Integer pageNumber=getParaToInt("pageNum");
		Integer department=getParaToInt("department");
		if(pageNumber==null){
			pageNumber=1;
		}
       if(department!=null){
    	   setAttr("expert", service.paginate(getParaToInt(0, pageNumber), 12,department));
    	   System.out.println(service.paginate(getParaToInt(0, pageNumber), 12,department).getList());
		}
       else{
    		setAttr("expert", service.paginates(getParaToInt(0, pageNumber), 12));
       }
	    
		setAttr("department", Db.find("select * from department "));
		setAttr("name", "专家风采");
		setAttr("departments", department);
		List<Record>  friendlinks=Db.findByCache("zone", "frindlink", "select * from friendlink order by flag asc");
		setAttr("firendlink", friendlinks);
		setAttr("rexpert", Db.find("select * from expert order by rand() limit 10"));
		render("index.html");
	}
	public void form(){	
		Expert expert=null;
		Integer id=getParaToInt("id");	
		if (id!=null && id>0) {
			 setAttr("expert", service.findById(id));
		     expert= service.findById(id);
			 setAttr("name",expert.getName());
		}
		
		setAttr("department", Db.find("select * from department "));
		setAttr("rexpert", Db.find("select * from expert order by rand() limit 10"));
		render("info.html");
	}

}
